package sudroid.android;

import android.os.Environment;
import android.util.Log;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import sudroid.LogUtils;

public class Logger
{
  private static final int BUFFER_SIZE = 102400;
  private static BufferedOutputStream bos;
  private static int level;
  private static File logFile;
  private static SimpleDateFormat sdf;
  private static boolean writeToLogFile = 1;

  static
  {
    level = 3;
    sdf = new SimpleDateFormat("HH:mm:ss.SSS");
  }

  private static void changeLogFile(File paramFile)
  {
    if ((logFile == null) || (!logFile.exists()))
    {
      logFile = paramFile;
      if (logFile.exists());
    }
    while (true)
    {
      try
      {
        boolean bool = logFile.createNewFile();
        return;
      }
      catch (IOException localIOException1)
      {
        StringBuilder localStringBuilder1 = new StringBuilder("Can't create logger file \"");
        String str1 = logFile.getAbsolutePath();
        LogUtils.e(str1 + "\"!");
        LogUtils.e(localIOException1);
        continue;
      }
      if (paramFile.exists())
      {
        try
        {
          FileUtil.copy(logFile, paramFile);
          FileUtil.delete(logFile);
          logFile = paramFile;
        }
        catch (IOException localIOException2)
        {
          StringBuilder localStringBuilder2 = new StringBuilder("Can't copy \"");
          String str2 = logFile.getAbsolutePath();
          StringBuilder localStringBuilder3 = localStringBuilder2.append(str2).append("\" to \"");
          String str3 = paramFile.getAbsolutePath();
          LogUtils.e(str3 + "\"!");
          LogUtils.e(localIOException2);
        }
        continue;
      }
      FileUtil.renameTo(logFile, paramFile);
    }
  }

  public static void congifLogFile(File paramFile)
  {
    if (bos != null);
    while (true)
    {
      return;
      if ((paramFile != null) && (paramFile.isFile()))
      {
        changeLogFile(paramFile);
        continue;
      }
      if (logFile != null)
        continue;
      if (!Environment.getExternalStorageState().equals("mounted"))
      {
        LogUtils.e("Can't create logger file. There is no media mounted!");
        continue;
      }
      initDefaultLogFile();
      initSimpleDateFormat();
    }
  }

  public static void d(String paramString)
  {
    if (level > 3);
    while (true)
    {
      return;
      if (writeToLogFile)
      {
        String str = LogUtils.getTag().toString();
        writingToLogFile(3, str, paramString);
      }
      LogUtils.d(paramString);
    }
  }

  public static void d(String paramString1, String paramString2)
  {
    if (level > 3);
    while (true)
    {
      return;
      if (writeToLogFile)
        writingToLogFile(3, paramString1, paramString2);
      LogUtils.d(paramString2);
    }
  }

  public static void e(String paramString)
  {
    if (level > 6);
    while (true)
    {
      return;
      if (writeToLogFile)
      {
        String str = LogUtils.getTag().toString();
        writingToLogFile(6, str, paramString);
      }
      LogUtils.e(paramString);
    }
  }

  public static void e(String paramString1, String paramString2)
  {
    if (level > 6);
    while (true)
    {
      return;
      if (writeToLogFile)
        writingToLogFile(6, paramString1, paramString2);
      LogUtils.e(paramString2);
    }
  }

  public static void e(String paramString, Throwable paramThrowable)
  {
    if (level > 6);
    while (true)
    {
      return;
      if (writeToLogFile)
      {
        String str = Log.getStackTraceString(paramThrowable);
        writingToLogFile(6, paramString, str);
      }
      LogUtils.e(paramThrowable);
    }
  }

  public static void e(Throwable paramThrowable)
  {
    if (level > 6);
    while (true)
    {
      return;
      if (writeToLogFile)
      {
        String str1 = LogUtils.getTag().toString();
        String str2 = Log.getStackTraceString(paramThrowable);
        writingToLogFile(6, str1, str2);
      }
      LogUtils.e(paramThrowable);
    }
  }

  public static int getLevel()
  {
    return level;
  }

  public static File getLogFile()
  {
    return logFile;
  }

  public static void i(String paramString)
  {
    if (level > 4);
    while (true)
    {
      return;
      if (writeToLogFile)
      {
        String str = LogUtils.getTag().toString();
        writingToLogFile(4, str, paramString);
      }
      LogUtils.i(paramString);
    }
  }

  public static void i(String paramString1, String paramString2)
  {
    if (level > 4);
    while (true)
    {
      return;
      if (writeToLogFile)
        writingToLogFile(4, paramString1, paramString2);
      LogUtils.i(paramString2);
    }
  }

  private static void initDefaultLogFile()
  {
    File localFile = Environment.getExternalStorageDirectory();
    logFile = new File(localFile, "logger_utf8.txt");
    try
    {
      boolean bool = logFile.createNewFile();
      return;
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        StringBuilder localStringBuilder = new StringBuilder("Can't create logger file \"");
        String str = logFile.getAbsolutePath();
        LogUtils.e(str + "\"!");
        LogUtils.e(localIOException);
      }
    }
  }

  private static void initSimpleDateFormat()
  {
    SimpleDateFormat localSimpleDateFormat = sdf;
    TimeZone localTimeZone = TimeZone.getTimeZone("CST");
    localSimpleDateFormat.setTimeZone(localTimeZone);
  }

  public static boolean isLogFileWritable()
  {
    return writeToLogFile;
  }

  public static void setLevel(int paramInt)
  {
    if ((paramInt > 7) || (paramInt < 3));
    while (true)
    {
      return;
      level = paramInt;
    }
  }

  public static void setLogFileWritable(boolean paramBoolean)
  {
    writeToLogFile = paramBoolean;
  }

  public static boolean startLogging()
  {
    try
    {
      congifLogFile(null);
      File localFile = logFile;
      FileOutputStream localFileOutputStream = new FileOutputStream(localFile, 1);
      bos = new BufferedOutputStream(localFileOutputStream, 102400);
      i = 1;
      return i;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
      {
        StringBuilder localStringBuilder = new StringBuilder("Can't open logger file \"");
        String str = logFile.getAbsolutePath();
        LogUtils.e(str + "\"!");
        LogUtils.e(localFileNotFoundException);
        int i = 0;
      }
    }
  }

  public static void stopLogging()
  {
    if (bos == null);
    while (true)
    {
      return;
      try
      {
        bos.flush();
        bos.close();
        bos = null;
        continue;
      }
      catch (IOException localIOException)
      {
        StringBuilder localStringBuilder = new StringBuilder("Can't close logger file \"");
        String str = logFile.getAbsolutePath();
        LogUtils.e(str + "\"!");
        LogUtils.e(localIOException);
        bos = null;
        continue;
      }
      finally
      {
        bos = null;
      }
    }
    throw localObject;
  }

  public static void w(String paramString)
  {
    if (level > 5);
    while (true)
    {
      return;
      if (writeToLogFile)
      {
        String str = LogUtils.getTag().toString();
        writingToLogFile(5, str, paramString);
      }
      LogUtils.w(paramString);
    }
  }

  public static void w(String paramString1, String paramString2)
  {
    if (level > 5);
    while (true)
    {
      return;
      if (writeToLogFile)
        writingToLogFile(5, paramString1, paramString2);
      LogUtils.w(paramString2);
    }
  }

  private static void writingToLogFile(int paramInt, String paramString1, String paramString2)
  {
    if (bos == null)
      throw new IllegalStateException("Maybe you havn't opened logger file!");
    try
    {
      localStringBuilder1 = new StringBuilder();
      switch (paramInt)
      {
      default:
        StringBuilder localStringBuilder2 = localStringBuilder1.append("UNKNOWN LEVEL/");
      case 3:
        while (true)
        {
          StringBuilder localStringBuilder3 = localStringBuilder1.append(paramString1).append("(");
          SimpleDateFormat localSimpleDateFormat = sdf;
          Date localDate = new Date();
          String str1 = localSimpleDateFormat.format(localDate);
          StringBuilder localStringBuilder4 = localStringBuilder3.append(str1).append("): ").append(paramString2).append("\n");
          BufferedOutputStream localBufferedOutputStream = bos;
          byte[] arrayOfByte = localStringBuilder1.toString().getBytes("UTF-8");
          localBufferedOutputStream.write(arrayOfByte);
          bos.flush();
          return;
          StringBuilder localStringBuilder5 = localStringBuilder1.append("D/");
        }
      case 4:
      case 5:
      case 6:
      }
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
      {
        StringBuilder localStringBuilder6 = new StringBuilder("Can't find \"");
        String str2 = logFile.getAbsolutePath();
        LogUtils.e(str2 + "\"!");
        LogUtils.e(localFileNotFoundException);
        continue;
        StringBuilder localStringBuilder7 = localStringBuilder1.append("I/");
      }
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      while (true)
      {
        StringBuilder localStringBuilder8 = new StringBuilder("Can't write UTF-8 character to \"");
        String str3 = logFile.getAbsolutePath();
        LogUtils.e(str3 + "\"!");
        LogUtils.e(localUnsupportedEncodingException);
        continue;
        StringBuilder localStringBuilder9 = localStringBuilder1.append("W/");
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        StringBuilder localStringBuilder1;
        LogUtils.e("I/O error when writting to logger file!");
        LogUtils.e(localIOException);
        continue;
        StringBuilder localStringBuilder10 = localStringBuilder1.append("E/");
      }
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.android.Logger
 * JD-Core Version:    0.6.0
 */